<?php
/**
 * 微教育模块
 *
 * @author 高贵血迹
 */
        global $_W, $_GPC;
        $weid = $this->weid;
        $from_user = $this->_fromuser;
		$schoolid = intval($_GPC['schoolid']);
		$openid = $_W['openid'];
        
        //查询是否用户登录		
		$userid = pdo_fetch("SELECT * FROM " . tablename($this->table_user) . " where :schoolid = schoolid And :weid = weid And :openid = openid And :sid = sid", array(':weid' => $weid, ':schoolid' => $schoolid, ':openid' => $openid, ':sid' => 0), 'id');
		
		$it = pdo_fetch("SELECT * FROM " . tablename($this->table_user) . " where weid = :weid AND id=:id ORDER BY id DESC", array(':weid' => $weid, ':id' => $userid['id']));	
		
		$school = pdo_fetch("SELECT * FROM " . tablename($this->table_index) . " where weid = :weid AND id=:id ORDER BY ssort DESC", array(':weid' => $weid, ':id' => $schoolid));
		
		$teachers = pdo_fetch("SELECT * FROM " . tablename($this->table_teachers) . " where weid = :weid AND id = :id", array(':weid' => $_W ['uniacid'], ':id' => $it['tid']));		

		$category = pdo_fetchall("SELECT * FROM " . tablename($this->table_classify) . " WHERE weid = :weid AND schoolid = :schoolid ORDER BY sid ASC, ssort DESC", array(':weid' => $_W['uniacid'], ':schoolid' => $schoolid), 'sid');
		if ($_GPC['getalist']) {
			$pageSize = intval($_GPC['pageSize']);
			$nowPage = intval($_GPC['nowpage']);
			$item_per_page = empty($_GPC['pageSize']) ? 10 : intval($_GPC['pageSize']);
			$page_number = max(1, intval($_GPC['nowpage']));
			if(!is_numeric($page_number)){
	   			header('HTTP/1.1 500 Invalid page number!');  
	    		exit();  
			}
			$position = ($page_number-1) * $item_per_page;	
		    $leave1 = pdo_fetchall("SELECT id,bj_id,title,tname,createtime FROM " . tablename($this->table_notice) . " where weid = '{$weid}' And schoolid = '{$schoolid}' And type = 2 ORDER BY createtime DESC LIMIT " . $position . ',' . $item_per_page );
			
			foreach($leave1 as $key =>$row){
				$leave1[$key]['name'] = $row['tname']."老师";
				//$list2 = pdo_fetchall("SELECT id FROM ".tablename($this->table_record)." WHERE weid = '{$weid}' And schoolid = '{$schoolid}' And noticeid = '{$row['id']}' And readtime > 5000 ");
				//$leave1[$key]['ydrs'] = "已读".count($list2)."人";	
				$leave1[$key]['time'] = date('m-d H:i', $row['createtime']);	
			}
			$datas = array(
			'ret' => array('code' => '200','msg' => 'success'),
			'data' => array(
						'dataList' => $leave1,
						'nowPage' => $nowPage,
							)
					);
					
			echo json_encode($datas);
			exit;
		}        		
        if(!empty($userid['id'])){
			
			$teacher = pdo_fetchall("SELECT * FROM " . tablename($this->table_teachers) . " where weid = :weid ORDER BY id DESC", array(':weid' => $_W ['uniacid']), 'id');
						
		    // $leave = pdo_fetchall("SELECT * FROM " . tablename($this->table_notice) . " where :schoolid = schoolid And :weid = weid And :tid = tid And :type = type ORDER BY createtime DESC", array(
		         // ':weid' => $weid,
				 // ':schoolid' => $schoolid,
				 // ':type' => 2,
				 // ':tid' => $teachers['id']
				 // ));
            //取本登录老师的群发消息（校长不取）
			$leave = pdo_fetchall("SELECT * FROM " . tablename($this->table_notice) . " where :schoolid = schoolid And :weid = weid And :type = type ORDER BY createtime DESC", array(
		         ':weid' => $weid,
				 ':schoolid' => $schoolid,
				 ':type' => 2
				 ));				
			include $this->template(''.$school['style3'].'/mnoticelist');
        }else{
			include $this->template('bangding');
        }        
?>